﻿<!DOCTYPE html>
<!--承包商入场工具管理编辑-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

    <!-- 行内编辑 css-->
    <style>
        .tb-edit .el-input {
            display: none
        }

        .tb-edit .current-row .el-input {
            display: block
        }

        .tb-edit .current-row .el-input+span {
            display: none
        }

        .tb-edit .el-select {
            display: none
        }

        .tb-edit .current-row .el-select {
            display: block
        }

        .tb-edit .current-row .el-select+span {
            display: none
        }

        .xian {
            display: block;
            text-align: center;
        }

        .yin {
            display: none;
            text-align: center;
        }

        .lineMust {
            position: absolute;
            right: 15px;
            bottom: 6px;
            bottom: 3px\0 !important;
            /* 兼容ie */
        }
    </style>
    <!-- 行内编辑 css-->
</head>

<body>
    <div id="app" v-cloak class="popupW100">
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="140px"
            size="mini">

            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                      
                                <!--type="text" v-model="Form.ContractorName" autocomplete="off" :disabled="true"-->
                                <template slot="prepend">
                                    {{ContractorAdmissionTool.ContractorName+mark.m}}
                                </template>
                                <el-select @visible-change="visibleChange" v-model="CBSListId" slot="suffix" @change="postChange" style="margin-left: 150px;">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in CBS_Lists" :label="item.contractorName"
                                               :value="item.id"></el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" offset="2" style="height:38px;">
                    <el-button type="primary" @click="ContractorInput('tj')">{{col.Choose}}</el-button>
                </el-col>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.headUser" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{ContractorAdmissionTool.PersonnelName+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.phone" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{ContractorAdmissionTool.phone+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <!--<el-col :span="11" :offset="2">
            <div class="elst-select-mini">
                <el-form-item>
                    <el-input type="text" v-model="Form.CarryingToolName" autocomplete="off" size="mini">
                        <template slot="prepend">
                            {{ContractorAdmissionTool.CarryingToolName+mark.m}}
                        </template>
                    </el-input>
                </el-form-item>
            </div>
        </el-col>-->
            </el-row>
            <!--<el-row>
        <el-col :span="11">
            <el-form-item :label="ContractorAdmissionTool.CarryingToolQuantity+mark.m" class="inputTextarea">

                <el-input-number v-model="Form.CarryingToolQuantity" @change="handleChange" :min="1"></el-input-number>
            </el-form-item>
        </el-col>
        <el-col :span="11" :offset="2">
            <el-form-item :label="ContractorAdmissionTool.IsConsumables+mark.m" prop="IsConsumables">
                <el-radio-group v-model="Form.IsConsumables" style="margin-top:5px">
                    <el-radio v-for="item in IsConsumables" :label="item.value" :value="item.key">{{item.value}}</el-radio>
                </el-radio-group>
            </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item :label="ContractorAdmissionTool.ArrivalTime+mark.m" prop="ArrivalTime">
                <el-date-picker v-model="Form.ArrivalTime"
                                type="datetime"
                                placeholder="选择日期时间">
                </el-date-picker>
            </el-form-item>
        </el-col>
    </el-row>-->
            <el-row>
                <el-col class="head-tool">
                    <el-button type="primary" @click="add">添加工具</el-button>
                </el-col>
            </el-row>
            <el-row>
                <el-col span="24">
                    <!--表格开始-->
                    <el-table ref="table" stripe @current-change="tableHandleCurrentChange" class="tb-edit"
                              :data="Form.ToolList" :row-key="getRowKeys" border
                              @selection-change="handleSelectionChange" row-style="height:10px" style="width: 100%;">

                        <el-table-column prop="carryingToolName" :label="ContractorAdmissionTool.CarryingToolName"
                                         show-overflow-tooltip="true">
                            <template scope="scope">
                                <el-input size="mini" v-model="scope.row.carryingToolName" placeholder="请输入内容">
                                </el-input>
                                <span>{{scope.row.carryingToolName}}</span>
                                <span class="lineMust" v-if="scope.row.carryingToolName.length<=0">
                                    <!-- 必填项添加 -->
                                    <img src="/static/images/exclamation.png" alt="">
                                </span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="carryingToolQuantity" :label="ContractorAdmissionTool.InCarryingQuantity"
                                         show-overflow-tooltip="true">
                            <template scope="scope">
                                <el-input size="mini" v-model="scope.row.carryingToolQuantity" placeholder="请输入内容">
                                </el-input>
                                <span>{{scope.row.carryingToolQuantity}}</span>
                                <span class="lineMust" v-if="scope.row.carryingToolQuantity.length<=0">
                                    <!-- 必填项添加 -->
                                    <img src="/static/images/exclamation.png" alt="">
                                </span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="toolChecker" :label="ContractorAdmissionTool.ToolInspector"
                                         show-overflow-tooltip="true">
                            <template scope="scope">
                                <el-input size="mini" v-model="scope.row.toolChecker" placeholder="请输入内容">
                                </el-input>
                                <span>{{scope.row.toolChecker}}</span>
                                <span class="lineMust" v-if="scope.row.toolChecker.length<=0">
                                    <!-- 必填项添加 -->
                                    <img src="/static/images/exclamation.png" alt="">
                                </span>
                            </template>
                        </el-table-column>

                        <el-table-column width="90" prop="update" label="编辑">
                            <template slot-scope="scope">
                                <span class="start xian">
                                    <button type="button" class="elst-bt-xg"
                                            @click=Edit('xg',scope.row.id,scope.$index)>
                                        <i class="el-icon-edit"></i>
                                    </button>
                                </span>
                                <span class="end yin">
                                    <button type="button" class="elst-bt-xg " @click="Save(scope.$index, scope.row)">
                                        <i class="el-icon-circle-check-outline"></i>
                                        <!-- 保存 -->
                                    </button>
                                    <!--<button type="button" @click.native.prevent="deleteRow(scope.$index, Form.CarryingToolList)">-->
                                    <button type="button" class="elst-bt-xg " @click="Back(scope.$index, scope.row)">
                                        <i class="el-icon-circle-close-outline"></i>
                                        <!-- 撤销 -->
                                    </button>
                                </span>
                            </template>
                        </el-table-column>
                        <el-table-column width="90" label="操作" align="center">
                            <template slot-scope="scope">
                                <button type="button" class="elst-bt-xg"
                                        @click="deleteRow(scope.$index, Form.ToolList)">
                                    <i class="el-icon-delete"></i>
                                </button>
                            </template>
                        </el-table-column>
                        <el-table-column prop="id" width="1" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span>{{scope.row.id}}</span>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-col>
            </el-row>
            <br />
            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>
                    <el-button type="primary" @click="onBack">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
        <el-dialog :title="title" fullscreen="true" :visible.sync="ListItem.dialogVisible" @close='closeDialog'
            width="80%" height="80%" top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:95%;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">
        var app = new Vue({
            el: '#app',
            data: {
                id: '',
                title: '',
                CBS_Lists: [],
                CBSListId: null,
                //业务表单内容
                Form: {
                    id: guidEmpty,
                    headUser: '', //姓名
                    CarryingToolList: [], //携带工具名称
                    CarryingToolQuantity: '', //入场携带工具数量
                    phone: '', //电话号
                    IsConsumables: '', //是否为消耗品
                    ContractorName: '', //承包商名称
                    ArrivalTime: '', //进场时间
                    SituationStatement: '', //情况说明
                    OutCarryingQuantity: '', //出场携带工具数量
                    DepartureTime: '', //离场时间
                    ContractorAdmissionTool: '',
                    cbs_OutFactoryTool: [],
                    ToolList:[]
                },
                IsConsumables: [],
                ListItem: ListItem,
                //表单验证
                rules: {
                    headUser: [
                        verification.NotNull,
                        {
                            pattern: verification.StringLengthAtoB.t.format(2, 5),
                            message: verification.StringLengthAtoB.m.format(2, 5),
                            trigger: 'blur'
                        }
                    ],
                    phone: [
                        verification.NotNull,
                        {
                            pattern: verification.StringLengthAtoB.t.format(5, 50),
                            message: verification.StringLengthAtoB.m.format(5, 10),
                            trigger: 'blur'
                        }
                    ],

                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },// 行内编辑 js
                add: function (formName) {
                    //if (this.formInline.model.classification == undefined) {
                    //    showMessage('必须选择评估类型!', 'error'); return;
                    //}
                    //alert('xxxxxxx');
                    if ($('tbody tr').attr("class") == "el-table__row current-row") {
                        showMessage(msg.EditingNotCompleted, 'error');
                    } else {

                        //this.lsForm.department = '';//添加是清空录入数据的，每一项都要有
                        //this.lsForm.evaluator = '';//添加是清空录入数据的，每一项都要有
                        //this.lsForm.post = '';//添加是清空录入数据的，每一项都要有
                        //this.lsForm.straightLine = '';//添加是清空录入数据的，每一项都要有
                        //this.lsForm.remarks = '';//添加是清空录入数据的，每一项都要有

                        //this.Form.department = '';//添加是清空录入数据的，每一项都要有
                        //this.Form.evaluator = '';//添加是清空录入数据的，每一项都要有
                        //this.Form.post = '';//添加是清空录入数据的，每一项都要有
                        //this.Form.straightline = '';//添加是清空录入数据的，每一项都要有
                        //this.Form.remarks = '';//添加是清空录入数据的，每一项都要有


                        $('.el-table__row').removeClass('current-row');
                        $('.el-table__row span.end').removeClass('xian');
                        $('.el-table__row span.end').addClass('yin');
                        $('.el-table__row span.start').removeClass('yin');
                        $('.el-table__row span.start').addClass('xian');

                        //if (!this.Form.ToolList) {
                        //    this.Form.ToolList = [];
                        //}


                        var newObj = {
                            carryingToolName: '',//添加是清空录入数据的，每一项都要有
                            carryingToolQuantity: '',//添加是清空录入数据的，每一项都要有
                            toolChecker: '',//添加是清空录入数据的，每一项都要有
                        }
                        this.Form.ToolList.unshift(newObj);
                        //this.Form.CarryingToolList.unshift(this.Form);

                        console.log("abegf", this.Form.ToolList);
                        setTimeout(function () {
                            $('.el-table__row:eq(0)').addClass('current-row');
                            $('.el-table__row:eq(0) span.end').removeClass('yin');
                            $('.el-table__row:eq(0) span.end').addClass('xian');
                            $('.el-table__row:eq(0) span.start').removeClass('xian');
                            $('.el-table__row:eq(0) span.start').addClass('yin');
                        }, 100);
                    }
                },
                //修改
                Edit: function (val, id, index) {
                    $('.el-table__row').removeClass('current-row');
                    $('.el-table__row:eq(' + index + ')').addClass('current-row');
                    $('.el-table__row span.end').removeClass('xian');
                    $('.el-table__row span.end').addClass('yin');
                    $('.el-table__row span.start').removeClass('yin');
                    $('.el-table__row span.start').addClass('xian');
                    $('.el-table__row:eq(' + index + ') span.end').removeClass('yin');
                    $('.el-table__row:eq(' + index + ') span.end').addClass('xian');
                    $('.el-table__row:eq(' + index + ') span.start').removeClass('xian');
                    $('.el-table__row:eq(' + index + ') span.start').addClass('yin');
                },
                // 保存 注意去掉mock中的parent 否则无法保存
                Save: function (a, b) {
                    if (!b.carryingToolName || !b.carryingToolQuantity || !b.toolChecker) {
                        showMessage(msg.NoMust, 'error');
                    }
                    else if (parseInt(b.carryingToolQuantity)<=0) {
                        showMessage('工具数量必须大于0!', 'error');
                    }
                    else {
                        // this.onSubmitForm('ruleForm', b);
                        //this.onSubmitForm('form', b);


                        //var newObj = {};
                        //$.extend(true, newObj, this.lsForm);

                        //console.log('newObj', newObj)
                        // this.Form.CarryingToolList.unshift(newObj);





                        $('.el-table__row').removeClass('current-row');
                        console.log("a", a);
                        console.log("b", b);
                        $('.el-table__row span.end').removeClass('xian');
                        $('.el-table__row span.end').addClass('yin');
                        $('.el-table__row span.start').removeClass('yin');
                        $('.el-table__row span.start').addClass('xian');
                        //初始化数据
                        // this.GetPageData(1);
                    }
                },
                Back: function (a, b) {
                    $('.el-table__row').removeClass('current-row');
                    $('.el-table__row span.end').removeClass('xian');
                    $('.el-table__row span.end').addClass('yin');
                    $('.el-table__row span.start').removeClass('yin');
                    $('.el-table__row span.start').addClass('xian');
                    //初始化数据
                    // this.GetPageData(1);
                    this.getData();
                },

                handblur: function () {
                    //this.$refs.table.setCurrentRow(999);
                    //console.log("c", 'c');
                },
                //table选中行handle
                tableHandleCurrentChange: function (currentRow) {
                    this.currSeelctId = currentRow.id;
                    this.currSeelctCell = currentRow;
                },
                //删除列表行
                deleteRow: function (index, rows) {
                    //rows.splice(index, 1);
                    var mythis = this; if (mythis.Form.ToolList[index].id == null || mythis.Form.ToolList[index].id == "" || mythis.Form.ToolList[index].id == undefined) {
                        rows.splice(index, 1);
                    } else {
                        myAjax("post", mythis, '/api/CBS_IntoFactoryTool/DeleteMuti', [mythis.Form.ToolList[index].id], function (response) {
                            rows.splice(index, 1);
                        });
                    }
                },
                // 行内编辑 js



                handleChange: function (value) {
                    console.log(value);
                },
                //提交数据
                onSubmitForm: function (formName) {
                    //var mythis = this;
                    //this.$refs[formName].validate(function (valid) {
                    //    //验证通过
                    //    if (valid) {
                    //        onSubmitForm(this, '/api/CBS_IntoFactoryTool/Save', mythis.Form);
                    //    } else {
                    //        //验证失败
                    //        return false;
                    //    }
                    //});
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {

                            if (mythis.CBSListId == null || mythis.CBSListId == "") {
                                alert("请选择承包商名称！");
                                return;
                            } else if (mythis.Form.headUser == null || mythis.Form.headUser  == "") {
                                alert("请输入负责人！");
                                return;
                            } else if (mythis.Form.phone == null || mythis.Form.phone == "") {
                                alert("请输入负责人电话！");
                                return;
                            } else {
                                //onSubmitForm(this, '/api/CBS_IntoFactoryTool/Save', mythis.Form.ToolList[i]);
                                for (var i = 0; i < mythis.Form.ToolList.length; i++) {
                                    //mythis.Form.ToolList[i].id = mythis.Form.CBSListId;
                                    
                                    mythis.Form.ToolList[i].CBSListId = mythis.CBSListId;
                                    mythis.Form.ToolList[i].headUser = mythis.Form.headUser;
                                    mythis.Form.ToolList[i].phone = mythis.Form.phone;
                                    onSubmitForm(this, '/api/CBS_IntoFactoryTool/Save', mythis.Form.ToolList[i]);
                                }
                            }
                               
                            
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getData: function () {
                    //getData(this, '/api/CBS_IntoFactoryTool/get?id=' + this.id);
                    var mythis = this;
                    if (mythis.id != null && mythis.id != '') {
                        myAjax("get", mythis, '/api/CBS_IntoFactoryTool/get?id=' + this.id, null, function (response) {
                            var ajaxModel = response.data;
                            mythis.Form = ajaxModel;
                            mythis.CBSListId = ajaxModel.cbsListId;
                            myAjax("post", this, '/api/CBS_User/GetList', { model: { status: '', CreateFactory: null, CBSListId: mythis.CBSListId }, offset: 0, limit: 100 }, function (response) {
                                mythis.CBS_UserLists = response.data.pageData;
                                //console.log('h1', response.data.pageData);
                                myAjax("post", this, '/api/CBS_IntoFactoryTool/GetList', { model: { cbsListId: ajaxModel.cbsListId, headUser: ajaxModel.headUser, phone: ajaxModel.phone, arrivalTime: ajaxModel.arrivalTime, admissionConfirmer: ajaxModel.admissionConfirmer }, offset: 0, limit: 100 }, function (response) {
                                    var ToolList = response.data.pageData;
                                    
                                    mythis.Form.ToolList = ToolList;
                                    //console.log('h1', response.data.pageData);
                                }, false);
                            }, false);


                            //mythis.userFrom.sex = mythis.userFrom.sex + "";
                        }, false);
                    }
                },
                ContractorInput: function (val, id) {
                    this.title = "承包商列表"
                    DialogShow(this, val, "ContractorDirectoryList.html", id);
                },
                UserInput: function (val, id) {
                    this.title = "工具管理"
                    DialogShow(this, val, "ContractorToolAdd.html", id);
                },
                onBack: function () {
                    parent.app.ListItem.dialogVisible = false;
                }
                 //初始化承包商下拉框
                ,getCBS_List: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/CBS_List/GetList', { model: { status: '', CreateFactory: null }, offset: 0, limit: 100 }, function (response) {
                        mythis.CBS_Lists = response.data.pageData;
                        //console.log('h1', response.data.pageData);
                    }, false);
                },
                postChange: function (val) {
                    //初始化承包商选项
                    if (this.id == null) {
                        this.CBS_UserLists = [];
                    }
                    this.CBSListId = val;
                    
                }
                , GetPageData: function () {

                }
            },
            mounted: function () {
                //this.IsConsumables = getDicData('50');
                this.id = getUrlParam("id");
                this.getCBS_List();
                this.getData();
            }
        });
    </script>
</body>

</html>